$(function() {
	//初始化数据
	initFeedbackListView();
});


// =====================主页========================
$(document).on("click", "#goHome", function() {
	$("#goHome").attr("href", $("#goHome").attr("href") + "&&identify=");
});

// ===================================================
$(document).on("click",".hrefClick",function() {
	var id = $(this).attr("defineId");
	$.ajax({
		url : rootPath + "/ui/eventfeedback/findEventReport/"+id,
		dataType : 'json',
		type : 'get',
		success : function(result) {
			var data = result.eventReport;
			jQuery('#reportEventVariable').text(data.reportEventVariable.title);
			jQuery('#reportEventType').text(data.reportEventType.eventName);
			jQuery('#reportContent').text(data.reportContent);
			jQuery('#reportMemo').text(data.reportMemo);
			var pic = data.reportImgAdress;
			if(pic == ""){
				pic =  rootPath + "/img/nopicture.png";
			}else{
				pic = rootPath +'/' + pic;
			}
			jQuery('#avatart').attr("src",pic);
			jQuery('#locationDes').text(data.reportAdress);
			
		}
	});
});
// ====================================构建页面================================
function bindingPage(str, data) {
	if (data.length == 0) {
		var contentval = '<li><h2 style="color:blue">暂无事件信息</h2></li>';
		$(str).append(contentval);
		//$(str).listview('refresh');
	}else{
		var contentval = '';
		for (var i = 0; i < data.length; i++) {
			contentval += '<br/><div class="div1">'
				+ '<a href="#FeedbackDetail" data-transition="slide" defindStr='+str+' class="hrefClick" defineId="'+ data[i].id + '">'
				+ '<div class="div-time">'
				+ '<div style="margin-left:20px;">'+ moment(data[i].reportAccTime).format('YYYY-MM-DD HH:mm') + '</div></div></a><br/>'
				+ '<div class="div-type">' + data[i].reportContent + '</div><br/>';
			contentval += '<div style="overflow: auto;padding-top:0;margin-left:20px;">'
				+ '<div class="div-inline"><p style="margin:0;">事件类型:'+data[i].reportEventType.eventName+'</p></div>'
				+ '<div class="div-inline"><p style="margin:0;">事件状态:'+data[i].reportEventVariable.title+'</p></div></div>'
				+ '</div>';
		}
		$(str).append(contentval);
	}
	$(str).listview('refresh');
};
// =============================我的上报事件列表=============================
function initFeedbackListView() {
	$.ajax({
		url : rootPath + "/ui/eventfeedback/getListView",
		dataType : 'json',
		type : 'get',
		success : function(result) {
			var data = result.list;
			bindingPage("#FeedbackListView", data);
		}
	});
};

